/*
day87
2019.11.23
*/
#include<stdlib.h>

struct TreeNode{
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
};



class Solution {
public:
	TreeNode* find(TreeNode *root,int key,TreeNode *&pre)
	{
		if(root->val==key) return root;
		
		pre=root;
		if(key<root->val)
		{
			return find(root->left,key,pre);
		}
		if(key>root->val)
		{
			return find(root->right,key,pre);
		}
	}
	
    TreeNode* deleteNode(TreeNode* root, int key) 
	{
		TreeNode *node = new TreeNode();
		TreeNode *del = new TreeNode();
		
		TreeNode *&pre=node;
        del = find(root,key,pre); 
        
        if(!pre)
        {
        	
		}
		else
		{
			if(!del->left && !del->right)
			{
				if(pre->left==del)
				{
					pre->left=NULL;
				}
				else
				{
					pre->right==NULL;
				}
			}
			else if(!del->left)
			{
				if(pre->left==del)
				{
					pre->left=del->right;
				}
				else
				{
					pre->right==del->right;
				}
			}
			else if(!del->right)
			{
				if(pre->left==del)
				{
					pre->left=del->left;
				}
				else
				{
					pre->right==del->left;
				}
			}
			else
			{
				
			}
		}
        return root;
    }
};


int main()
{
	return 0;
}
